package com.ys.controller.api.business;

import com.ys.entity.business.ThrCanvassApplyItem;
import com.ys.enume.flow.FlowEnum;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/api/inter/thrCanvassApplyItem")
public class ApiInterThrCanvassApplyItemController {

    @Autowired
    private CommonApiService<ThrCanvassApplyItem> commonApiService;
    /**
     * 弹出框调用
     */
    @RequestMapping("/searchForModal")
    @ResponseBody
    public LayuiTableVoJA searchForModal(Model model, HttpServletRequest request, HttpServletResponse response,
                                         @ModelAttribute ThrCanvassApplyItem cond
    ){
        cond.addLeftJoin("THR_CanvassApply C ON C.Bid = A.Pbid");

        cond.addField("P.Name AS pName");
        cond.addField("P.Id AS pInstitutionId");
        cond.addField("O.Name AS institutionName");
        cond.addLeftJoin("TS_OperateOrg O on O.Id = A.InstitutionId");
        cond.addLeftJoin("TS_OperateOrg P on P.Id = O.Pid");

        cond.addLeftJoin("TS_UserChange B on B.Id = C.Operateperson")
                //.addField("B.Id operatorUserChangeId")//运营人变更Id
                .addField("B.UserId operatorUserId")//运营人工号
                .addField("B.UserName operatorUserName")//运营人
                .addField("B.RoleName roleName")//运营人岗位
                .addField("B.DeptName deptName");//运营人部门

        cond.addLeftJoin("THR_OperateCompanyApply PO ON O.HeadVgsbm = PO.Vgsbm AND 1=1");
        cond.addField("PO.Vgsbm AS parentVgsbm");
        cond.addField("PO.Vgsjc AS parentVgsjc");


        cond.where("C.EffectStock = "+ FlowEnum.EffectStock.EFFECTED.value);//只查询已生效数据
        return commonApiService.searchLay(cond);
    }
}

